﻿/* 12. *** Write a program to read your age from the console and print how old you will be after 10 years. */

using System;

public class AgeAfterSomeYears
{
    private static byte myAge; //explicitly including 0
    private static int after = 10;
    private static string myAgeString;
    private static bool maybeTrue = false;
    private static byte oldestMan = 150;
    private static int? newRecord = null;

    public static void Main()
    {
        Console.Clear();
        do
        {
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Now Your age is ");
            myAgeString = Console.ReadLine();

            if (byte.TryParse(myAgeString, out myAge))
                if ((myAge <= oldestMan) || (myAge == newRecord))
                {
                    AfterDataInput();
                    Console.BackgroundColor = ConsoleColor.White;
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("Now Your age is {0} and after {1} years You will be {2} years old.",
                                        myAge, after, myAge + after);
                    maybeTrue = true;
                }
                else
                {
                    newRecord = myAge;
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("Are You sure You are oldest man forever times?\nEnter Your age again for confirmation!");
                }

            else
            {
                newRecord = null;
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Your age must be nonnegative integer number under 256!\nEnter it again!");
            }

        } while (!maybeTrue);

        Console.ForegroundColor = ConsoleColor.Black;

    }

    public static void AfterDataInput()
    {
        do
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Now Your age is {0}", myAge);
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Enter natural number for period \"AFTER\" : ", myAge);
            if (int.TryParse(Console.ReadLine(), out after))
                if (after >= 0)
                    break;

        } while (true);

        Console.Clear();
    }
}